package examples.fxroot

import de.saxsys.mvvmfx.ViewModel
import javafx.beans.property.*

/**
 * Created by TK-chenbin on 2015/6/5.
 */
class LabeledTextFieldViewModel implements ViewModel {
    private ReadOnlyStringWrapper labelText = new ReadOnlyStringWrapper("default")

    private ReadOnlyBooleanWrapper buttonDisabled = new ReadOnlyBooleanWrapper()

    private StringProperty inputText = new SimpleStringProperty()

    public LabeledTextField() {
        buttonDisabled.bind(inputText.isEmpty())
    }

    void changeLabel() {
        labelText.set(inputText.get())
        inputText.set("")
    }

    ReadOnlyStringProperty labelText() {
        return labelText.readOnlyProperty
    }

    ReadOnlyBooleanProperty buttonDisabled() {
        return buttonDisabled.readOnlyProperty
    }

    StringProperty inputText() {
        return inputText
    }

}
